<template>
  <div>
    <el-card>
      <el-form ref="form" :model="form" class="form" :inline="true" size="mini">
        <el-form-item label="店铺ID/昵称" class="name">
          <el-input v-model="form.shopName"></el-input>
        </el-form-item>
        <el-form-item label="用户ID/昵称" class="name">
          <el-input v-model="form.userName"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="form.status" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提现单号" class="name">
          <el-input v-model.number="form.num" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="申请提现日期">
          <el-date-picker
            v-model="applyTime"
            type="daterange"
            value-format="timestamp"
            :clearable="false"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            @change="change"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-button type="primary" size="small" @click="search">查询</el-button>
        <el-button size="small" @click="resetForm()">重置</el-button>
      </el-form>
    </el-card>

    <el-table  :data="tableData" row-key="id" class="customer-table">
      <el-table-column label="交易类型" align="center" width="100">
        <template slot-scope="{ row }">
          <span>{{ row.type === 1 ? "用户" : "店铺" }}提现</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺ID/用户ID" prop="id" align="center" width="80" />
      <el-table-column label="店铺昵称/用户昵称" align="center" width="200">
        <template slot-scope="{ row }">
          <span>{{
            row.shopName ? `${row.shopName}` : `${row.userName}`
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现单号" prop="num" align="center" />
      <el-table-column label="提现金额" prop="money" align="center" width="120" />
      <el-table-column label="申请提现时间" align="center" width="160">
        <template slot-scope="{ row }">
          <span>{{ row.applyTime | date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" align="center" width="120"/>
      <el-table-column label="提现时间" prop="arriveTime" align="center" width="160">
        <template slot-scope="{ row }">
          <span>{{ row.status === "已提现" ? `${row.arriveTime}` : "/"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现备注" prop="remark" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.status === "已提现" ? `${row.remark}` : "/" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" prop="operate" align="center">
        <template slot-scope="{ row }"  v-if="row.status==='已提现'?false:true">
          <el-button @click="handle(row)"  size="small"  type="primary" round>处理</el-button>
        </template>
      </el-table-column>
    </el-table>
   <el-row type="flex" justify="center" align="middle" style="height: 60px">
        <el-pagination
           :current-page="page.page"
            :page-size="page.size"
            :total="page.total"
            :page-sizes="[2, 3, 5, 10]"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        >
        </el-pagination>
      </el-row>
    <el-dialog
      :visible.sync="showDialog"
      :title="title"
      class="remark"
      :center="true"
      width="25%"
    >
      <el-form>
        <el-form-item label="备注">
          <el-input type="textarea" :rows="6" v-model="addRemark" placeholder="请填写备注"></el-input>
        </el-form-item>
      </el-form>
      <el-row slot="footer" type="flex" justify="center">
        <el-col>
          <el-button size="small" type="primary" @click="btnOk">确定</el-button>
          <el-button size="small" @click="btnCancel">取消</el-button>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { getWithdraw, handleWithdraw } from '@/api/withdraw.js'
import moment from 'moment'
import { queryFn } from '@/utils' // 多选项查询
export default {
  data () {
    return {
      addRemark: '',
      current: '',
      title: '',
      showDialog: false,
      currentPage4: 4,
      applyTime: '',
      options: [
        {
          value: '已提现',
          label: '已提现'
        },
        {
          value: '待处理',
          label: '待处理'
        }
      ],
      form: {
        status: '',
        shopName: '',
        userName: '',
        currentstatus: '',
        num: '',
        applyTime_gte: '',
        applyTime_lte: ''
      },
      tableData: [],
      page: {
        page: 1,
        size: 5,
        total: 7
      }
    }
  },
  created () {
    this.getWithdrawList()
  },
  filters: {
    date: function (value) {
      if (!value) return ''
      return moment(value).format('YYYY-MM-DD HH:mm:ss')
    }
  },
  methods: {
    // 获取页面数据
    async getWithdrawList () {
      const { data } = await getWithdraw()
      console.log(data)
      this.tableData = data
    },
    // 选取日期
    change (v) {
      // console.log(v)
      if (!v) return
      this.form.applyTime_gte = v[0]
      this.form.applyTime_lte = v[1]
    },
    // 查询
    async search () {
      const obj = queryFn(this.form)
      console.log(obj)
      const { data } = await getWithdraw(obj)
      console.log(data)
      this.tableData = data
      this.form.status = ''
      this.form.shopName = ''
      this.form.userName = ''
      this.form.num = ''
      this.form.applyTime_gte = ''
      this.form.applyTime_lte = ''
      this.applyTime = ''
      this.page.total = this.tableData.length
    },
    // 重置
    resetForm () {
      this.form.status = ''
      this.form.shopName = ''
      this.form.userName = ''
      this.form.num = ''
      this.form.applyTime_gte = ''
      this.form.applyTime_lte = ''
      this.applyTime = ''
      this.getWithdrawList()
    },
    // 点击处理
    handle (i) {
      this.showDialog = true
      // console.log(i)
      if (i.shopName) {
        this.title = `确认商户${i.shopName}提现申请已打款`
      } else {
        this.title = `确认用户${i.userName}提现申请已打款`
      }
      this.current = i
    },
    // 确认处理
    async btnOk () {
      console.log(this.addRemark)
      this.current.remark = this.addRemark
      this.current.status = '已提现'
      this.current.arriveTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
      console.log(this.current)
      await handleWithdraw(this.current.id, this.current)
      this.$message.success('处理成功')
      this.getWithdrawList()
      this.addRemark = ''
      this.showDialog = false
    },
    // 取消处理
    btnCancel () {
      this.showDialog = false
      this.addRemark = ''
    },
    // 分页
    async  handleSizeChange (newsize) {
      this.page.size = newsize
      const { data } = await getWithdraw({
        _page: this.page.page,
        _limit: this.page.size
      })
      this.tableData = data
    },
    async  handleCurrentChange (newpage) {
      this.page.page = newpage
      // console.log(newpage)
      const { data } = await getWithdraw({
        _page: this.page.page,
        _limit: this.page.size
      })
      this.tableData = data
    }
  }
}
</script>

<style lang="less" scoped>
// .remark {
//   width: 1000px;
//   height: 1000px;
// }

.el-card {
  margin-bottom: 30px;
}
.form {
  box-sizing: border-box;
}
/deep/.customer-table th {
  border: none;
  // background-color: rgb(170, 56, 56);
  // color: white;
  // border-radius: 5px;
}
.customer-table /deep/ th.el-table__cell.is-leaf {
  // background-color: rgb(233, 237, 250);

  border: none;
}
.customer-table /deep/ .el-table__row > td {
  border: none;
}
.customer-table /deep/ .el-table__row > td {
  border: none;
}
.el-button + .el-button {
  margin-left: 30px;
}
.el-form--inline .el-form-item {
  margin-right: 120px;
}
.customer-table th {
  border: none;
}
.customer-table td,
.customer-table th.is-leaf {
  border: none;
}
// 表格最外边框
.el-table--border,
.el-table--group {
  border: none;
}
// 头部边框
.customer-table thead tr th.is-leaf {
  border: 1px solid #ebeef5;
  border-right: none;
}
.customer-table thead tr th:nth-last-of-type(2) {
  border-right: 1px solid #ebeef5;
}
// 表格最外层边框-底部边框
.el-table--border::after,
.el-table--group::after {
  width: 0;
}
.customer-table::before {
  width: 0;
}
.customer-table .el-table__fixed-right::before,
.el-table__fixed::before {
  width: 0;
}
// 表格有滚动时表格头边框
.el-table--border th.gutter:last-of-type {
  border: 1px solid #ebeef5;
  border-left: none;
}
</style>
